package com.pp.controller;

import com.pp.entity.User;
import com.pp.mapper.UserMapper;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * Created by lanou on 18/2/27.
 */
@Controller
@RequestMapping("/")
public class HelloController {
    @Resource
    private JdbcTemplate jdbcTemplate;

    @Resource
    private UserMapper userMapper;

    @RequestMapping("hello")
    public ModelAndView hello(String name,ModelAndView mav){
        //mav.addObject("name",name);
//        System.out.println(name);
//        String sql = "select uname,upwd from user_info where uname=?";
//        RowMapper<User> rowMapper = new BeanPropertyRowMapper<User>(User.class);
//       User user =(User)jdbcTemplate.queryForObject(sql,rowMapper,name);
        User user = userMapper.findUserByUserName(name);
       mav.addObject("user",user);
       mav.setViewName("hello");
        return mav;
    }
}
